package com.maple.controller;

import com.maple.model.Account;
import com.maple.service.AccountService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * http://127.0.0.1:9000/account/maple
 * <p>
 * TaskController
 *
 * @author leihz
 * @date 2017/7/6 15:04
 */
@RestController
@RequestMapping("/account")
public class AccountController {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private AccountService accountService;


    @RequestMapping("/{name}")
    public Object getAccountByName(@PathVariable String name) {
        try {
            Account account = accountService.findAccountByName(name);
            if (account != null) {
                return account;
            }
            return "未查询到相关信息";
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("查看任务队列消息失败", e.getMessage());
            return "ERROR, 查看任务队列消息失败";
        }

    }

    @RequestMapping("/test")
    public Object accountTest() {
        try {
            return "未查询到相关信息";
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("查看任务队列消息失败", e.getMessage());
            return "ERROR, 查看任务队列消息失败";
        }

    }

}
